﻿// Fill out your copyright notice in the Description page of Project Settings.


#include "ElementUIUMG/Public/ElementUIMessage.h"
#include "Components/ElementUISlot.h"

// void UElementUIMessage::SynchronizeProperties() {}
// void UElementUIMessage::ReleaseSlateResources(bool bReleaseChildren) {}
// void UElementUIMessage::PostLoad() {}
// const FText UElementUIMessage::GetPaletteCategory() {}

UClass* UElementUIMessage::GetSlotClass() const
{
	return UElementUISlot::StaticClass();
}

void UElementUIMessage::OnSlotAdded(UPanelSlot* inSlot)
{
	UElementUISlot* BorderSlot = CastChecked<UElementUISlot>(inSlot);
	// BorderSlot->Padding = Padding;
	// BorderSlot->HorizontalAlignment = HorizontalAlignment;
	// BorderSlot->VerticalAlignment = VerticalAlignment;
	// // UE_LOG(LogTemp, Warning, TEXT("1"));
	if (ElementUIMessage.IsValid())
	{
		// // UE_LOG(LogTemp, Warning, TEXT("2"));
		BorderSlot->BuildSlot(ElementUIMessage.ToSharedRef());
	}
}

void UElementUIMessage::OnSlotRemoved(UPanelSlot* inSlot)
{
	if (ElementUIMessage.IsValid())
	{
		ElementUIMessage->SetContent(SNullWidget::NullWidget);
	}
}

void UElementUIMessage::SynchronizeProperties()
{
	Super::SynchronizeProperties();
}

void UElementUIMessage::ShowMessage()
{
	if(ElementUIMessage.IsValid())
	{
		ElementUIMessage->ShowMessage();
	}
}

void UElementUIMessage::HideMessage()
{
	if(ElementUIMessage.IsValid())
	{
		ElementUIMessage->HideMessage();
	}
}

void UElementUIMessage::ReleaseSlateResources(bool bReleaseChildren)
{
	Super::ReleaseSlateResources(bReleaseChildren);
	ElementUIMessage.Reset();
}

TSharedRef<SWidget> UElementUIMessage::RebuildWidget()
{
	ElementUIMessage=SNew(SElementUIMessage);
	if (GetChildrenCount() > 0)
	{
		Cast<UElementUISlot>(GetContentSlot())->BuildSlot(ElementUIMessage.ToSharedRef());
	}
	return ElementUIMessage.ToSharedRef();
}

#if WITH_EDITOR
const FText UElementUIMessage::GetPaletteCategory()
{
	return NSLOCTEXT("ElementUI", "ElementUICategory", "ElementUI");
}
#endif